﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KCMS.BusinessLogic.Interfaces;
using StructureMap;
using AutoMapper;
using KCMS.Web.Models;

namespace KCMS.Controllers
{
    public class NewsController : Controller
    {
        INewsService newsService = ObjectFactory.GetInstance<INewsService>();
        
        public ActionResult Latest(int count)
        {
            var news = newsService.getAllPublised();
            var model = Mapper.Map<IEnumerable<KCMS.BusinessLogic.Models.News>,IEnumerable<NewsViewModel>>(news);
            return PartialView(model.Take(count));
        }
        public ActionResult ShowAll()
        {
            var news = newsService.getAllPublised();
            var model = Mapper.Map<IEnumerable<KCMS.BusinessLogic.Models.News>, IEnumerable<NewsViewModel>>(news);
            return View(model);
        }
        public ActionResult Show(String code)
        {
            var news = newsService.getByCode(code);
            var model = Mapper.Map<KCMS.BusinessLogic.Models.News,NewsViewModel>(news);
            return View(model);
        }

    }
}
